| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | Static Public Member Functions | List of all members
nkGraphics::Mesh Class Reference

Holds information about a mesh. Used as a basis to render 3d models. More...

Inheritance diagram for nkGraphics::Mesh:

## Public Member Functions
virtual | ~Mesh ()
const BoundingBox & | getBounds () const
nkMemory::BufferView< unsigned char > | getVertexBuffer (unsigned int index) const
unsigned int | getVertexBufferStride (unsigned int index) const
unsigned int | getVertexBufferCount () const
nkMemory::BufferView< unsigned char > | getIndexBuffer () const
const MeshInputLayout & | getInputLayout () const
unsigned int | getId () const
unsigned int | getVertexCount () const
unsigned int | getIndexCount () const
PRIMITIVE_TOPOLOGY | getTopology () const
INDEX_FORMAT | getIndexFormat () const
bool | getAutoComputeBounds () const
void | setBounds (const BoundingBox &value)
void | addVertexBuffer (nkMemory::BufferView< unsigned char > view, unsigned int stride=0)
void | addVertexBufferCopy (nkMemory::BufferView< unsigned char > view, unsigned int stride=0)
void | addVertexBufferForward (nkMemory::Buffer &&buffer, unsigned int stride=0)
void | removeVertexBuffer (unsigned int index)
void | setIndexBuffer (nkMemory::BufferView< unsigned char > view)
void | setIndexBufferCopy (nkMemory::BufferView< unsigned char > view)
void | setIndexBufferForward (nkMemory::Buffer &&buffer)
void | setInputLayout (const MeshInputLayout &layout)
void | setId (unsigned int value)
void | setVertexCount (int value)
void | setIndexCount (int value)
void | setTopology (PRIMITIVE_TOPOLOGY value)
void | setIndexFormat (INDEX_FORMAT value)
void | setAutoComputeBounds (bool value)
void | computeBounds (nkMemory::StringView positionAttributeName)
virtual bool | load () override
virtual void | freeShadowBuffers ()
virtual void | exportClassToTree (nkExport::Node *rootNode) override
virtual void | importClassFromTree (nkExport::Node *rootNode) override
Public Member Functions inherited from nkGraphics::Resource
virtual | ~Resource ()
bool | isReadyForRendering () const
bool | isUnloaded () const
RESOURCE_LOAD_STATE | getLoadState () const
nkMemory::StringView | getPath () const
RESOURCE_TYPE | getTypeName () const
nkMemory::StringView | getName () const
System * | getSystem () const
bool | getHidden () const
bool | getGpuUploadCanBeDeferred () const
virtual void | setPath (nkMemory::StringView value)
void | setName (nkMemory::StringView value)
void | setHidden (bool value)
void | setGpuUploadCanBeDeferred (bool value)
virtual void | unload ()=0
Public Member Functions inherited from nkExport::Exportable
| Exportable () noexcept
virtual | ~Exportable ()

## Static Public Member Functions
static nkMemory::UniquePtr< Mesh > | create (System *system=nullptr)

## Detailed Description

Holds information about a mesh. Used as a basis to render 3d models.

See MeshManager::createOrRetrieve() or Mesh::create() for instantiation.

## Constructor & Destructor Documentation

## ◆ ~Mesh()

virtual nkGraphics::Mesh::~Mesh | ( |  | ) |
| virtual

Destructor.

## Member Function Documentation

## ◆ getBounds()

const BoundingBox& nkGraphics::Mesh::getBounds | ( |  | ) | const

Returns
  The bounds of the meshes, for reading purpose.

## ◆ getVertexBuffer()

nkMemory::BufferView<unsigned char> nkGraphics::Mesh::getVertexBuffer | ( | unsigned int | index | ) | const

Gives access to a given vertex buffer CPU memory.

Parameters

  index | The index of the buffer to query the memory from.

Returns
  A view over the buffer memory.

Remarks
  This method works as long as the shadow buffers have not been freed. It only has access to the CPU data.

## ◆ getVertexBufferStride()

unsigned int nkGraphics::Mesh::getVertexBufferStride | ( | unsigned int | index | ) | const

Gives access to the stride of a given vertex buffer.

Parameters

  index | The index of the vertex buffer to query from.

Returns
  The stride of given vertex buffer. It will either be the one specified when adding the buffer, or the automatically computed one if not.

## ◆ getVertexBufferCount()

unsigned int nkGraphics::Mesh::getVertexBufferCount | ( |  | ) | const

Returns
  The vertex buffer count.

## ◆ getIndexBuffer()

nkMemory::BufferView<unsigned char> nkGraphics::Mesh::getIndexBuffer | ( |  | ) | const

Gives access to the index buffer CPU memory.

Returns
  A view over the buffer memory.

Remarks
  This method works as long as the shadow buffers have not been freed. It only has access to the CPU data.

## ◆ getInputLayout()

const MeshInputLayout& nkGraphics::Mesh::getInputLayout | ( |  | ) | const

Gives access to the input layout of the mesh, for reading purposes.

Returns
  The input layout currently used by the mesh.

## ◆ getId()

unsigned int nkGraphics::Mesh::getId | ( |  | ) | const

Returns
  The id of the mesh.

## ◆ getVertexCount()

unsigned int nkGraphics::Mesh::getVertexCount | ( |  | ) | const

Returns
  The number of vertices.

## ◆ getIndexCount()

unsigned int nkGraphics::Mesh::getIndexCount | ( |  | ) | const

Returns
  The number of indices.

## ◆ getTopology()

PRIMITIVE_TOPOLOGY nkGraphics::Mesh::getTopology | ( |  | ) | const

Returns
  The topology used by the mesh.

## ◆ getIndexFormat()

INDEX_FORMAT nkGraphics::Mesh::getIndexFormat | ( |  | ) | const

Returns
  The index data format used.

## ◆ getAutoComputeBounds()

bool nkGraphics::Mesh::getAutoComputeBounds | ( |  | ) | const

Returns
  Whether the mesh auto-computes its bounds (true) or not (false).

## ◆ setBounds()

void nkGraphics::Mesh::setBounds | ( | const BoundingBox & | value | ) |

Allows to override the bounds of the mesh.

Parameters

  value | The bounds for the mesh to use.

## ◆ addVertexBuffer()

void nkGraphics::Mesh::addVertexBuffer | ( | nkMemory::BufferView< unsigned char > | view,
|  | unsigned int | stride = `0`
| ) |  |

Adds a vertex buffer, by referencing memory.

Parameters

  view | The memory to reference.
  stride | The stride of the buffer given (number of bytes to advance to get to next vertex information). If left to 0, it will be automatically computed from the layout, assuming tightly packed data.

Remarks
  With this method, the buffer simply gets referenced for later loading operation. This requires the memory given to remain available through the whole loading process. Use this method if you know memory lifetime is long enough for the mesh to use it.

## ◆ addVertexBufferCopy()

void nkGraphics::Mesh::addVertexBufferCopy | ( | nkMemory::BufferView< unsigned char > | view,
|  | unsigned int | stride = `0`
| ) |  |

Adds a vertex buffer, by copying memory.

Parameters

  view | The memory to copy.
  stride | The stride of the buffer given (number of bytes to advance to get to next vertex information). If left to 0, it will be automatically computed from the layout, assuming tightly packed data.

Remarks
  With this method, the buffer gets copied over. This implies a new allocation, and a copy operation. This function can be used to make sure data is safe within the mesh, without having to invalidate input.

## ◆ addVertexBufferForward()

void nkGraphics::Mesh::addVertexBufferForward | ( | nkMemory::Buffer && | buffer,
|  | unsigned int | stride = `0`
| ) |  |

Adds a vertex buffer, by forwarding memory.

Parameters

  buffer | The memory to forward.
  stride | The stride of the buffer given (number of bytes to advance to get to next vertex information). If left to 0, it will be automatically computed from the layout, assuming tightly packed data.

Remarks
  With this method, the buffer needs to be moved. This means that the memory will be forwarded into the mesh's own memory, invalidating input. This function can be used if memory will not be reused afterwards, and an efficient way of passing memory is wanted.

## ◆ removeVertexBuffer()

void nkGraphics::Mesh::removeVertexBuffer | ( | unsigned int | index | ) |

Removes a vertex buffer.

Parameters

  index | The index of the vertex buffer to remove from memory.

## ◆ setIndexBuffer()

void nkGraphics::Mesh::setIndexBuffer | ( | nkMemory::BufferView< unsigned char > | view | ) |

Sets the index buffer the mesh should use, by referencing it.

Parameters

  view | The memory to reference.

Remarks
  With this method, the buffer simply gets referenced for later loading operation. This requires the memory given to remain available through the whole loading process. Use this method if you know memory lifetime is long enough for the mesh to use it.

## ◆ setIndexBufferCopy()

void nkGraphics::Mesh::setIndexBufferCopy | ( | nkMemory::BufferView< unsigned char > | view | ) |

Sets the index buffer the mesh should use, by copying memory.

Parameters

  view | The memory to copy over.

Remarks
  With this method, the buffer gets copied over. This implies a new allocation, and a copy operation. This function can be used to make sure data is safe within the mesh, without having to invalidate input.

## ◆ setIndexBufferForward()

void nkGraphics::Mesh::setIndexBufferForward | ( | nkMemory::Buffer && | buffer | ) |

Sets the index buffer the mesh should use, by forwarding memory.

Parameters

  buffer | The buffer to get memory from.

Remarks
  With this method, the buffer needs to be moved. This means that the memory will be forwarded into the mesh's own memory, invalidating input. This function can be used if memory will not be reused afterwards, and an efficient way of passing memory is wanted.

## ◆ setInputLayout()

void nkGraphics::Mesh::setInputLayout | ( | const MeshInputLayout & | layout | ) |

Sets the input layout describing mesh data.

Parameters

  layout | The layout to use to interpret the mesh data.

## ◆ setId()

void nkGraphics::Mesh::setId | ( | unsigned int | value | ) |

Sets the id of the mesh. Used internally for tracking.

Parameters

  value | The id to use.

## ◆ setVertexCount()

void nkGraphics::Mesh::setVertexCount | ( | int | value | ) |

Sets the number of vertices of the mesh.

Parameters

  value | The number of vertices to use.

## ◆ setIndexCount()

void nkGraphics::Mesh::setIndexCount | ( | int | value | ) |

Sets the number of indices of the mesh.

Parameters

  value | The number of indices to use.

## ◆ setTopology()

void nkGraphics::Mesh::setTopology | ( | PRIMITIVE_TOPOLOGY | value | ) |

Sets the topology to use.

Parameters

  value | The primitive topology the mesh should use.

## ◆ setIndexFormat()

void nkGraphics::Mesh::setIndexFormat | ( | INDEX_FORMAT | value | ) |

Sets the format of indices stored in the index buffer.

Parameters

  value | The index format to use.

## ◆ setAutoComputeBounds()

void nkGraphics::Mesh::setAutoComputeBounds | ( | bool | value | ) |

Sets whether the loading step should compute the bounds of the mesh.

Parameters

  value | If the bounds should be computed (true) or not (false).

## ◆ computeBounds()

void nkGraphics::Mesh::computeBounds | ( | nkMemory::StringView | positionAttributeName | ) |

Manually triggers a bound computing.

Parameters

  positionAttributeName | The name of the position attribute within the layout to find back position data for bounds computing.

## ◆ load()

virtual bool nkGraphics::Mesh::load | ( |  | ) |
| override virtual

Loading function. A resource goes into different states through its lifetime.

- Created. It is awaiting configuration by external code. At this point, the resource can already be used everywhere, but it will have default values, often resulting in a no-op.
- Loading. The configuration has been made and the load function has been called. For some resources, this status is bypassed.
- Loaded. The resource has been loaded and all memory has been populated. At this point, the resource should operate as described.

It is possible to loop through these states during the resource lifetime, if needed.

Returns
  Whether the loading went well (true) or not (false).

Implements nkGraphics::Resource.

## ◆ freeShadowBuffers()

virtual void nkGraphics::Mesh::freeShadowBuffers | ( |  | ) |
| virtual

Frees the shadow buffers, aka the CPU buffers (vertex buffers and index buffer).
Can be called after loading the mesh to free requested memory.

## ◆ exportClassToTree()

virtual void nkGraphics::Mesh::exportClassToTree | ( | nkExport::Node * | rootNode | ) |
| override virtual

Exports an item into a tree describing its structure and its data.

Parameters

  rootNode | The node into which the object has to write its related information.

Implements nkExport::Exportable.

## ◆ importClassFromTree()

virtual void nkGraphics::Mesh::importClassFromTree | ( | nkExport::Node * | rootNode | ) |
| override virtual

Imports information from a tree which is supposed to describe its structure and data.

Parameters

  rootNode | The root node of the tree holding the information.

Implements nkExport::Exportable.

## ◆ create()

static nkMemory::UniquePtr<Mesh> nkGraphics::Mesh::create | ( | System * | system = `nullptr` | ) |
| static

Creates a standalone resource, linking it to a system, but no manager. This method can be used to allocate a resource and manually manage its lifetime.

Parameters

  system | The system to create the resource into. If left to nullptr, then the Singleton instance will be used.

Returns
  The created resource instance.

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsGraphics/Meshes/Mesh.h